package com.srlg.controller;

import com.srlg.model.entity.User;
import com.srlg.service.UserService;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.persistence.EntityManager;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;

/**
 * @desc:
 * @author: srlg li
 * @date: 2024/12/26 下午11:04
 */
@Path("/user")
@ApplicationScoped
@Produces("application/json")
@Consumes("application/json")
public class UserController {

    @Inject
    UserService userService;

    @Inject
    EntityManager entityManager;

    @POST
    @Path("/save")
    @Produces(MediaType.TEXT_PLAIN)
    public String addUser(@QueryParam(value = "name") String name, @QueryParam(value = "email") String email) {
        return userService.save(name, email);
    }

    @GET
    @Path("names")
    @Produces(MediaType.TEXT_PLAIN)
    public String names() {

        return userService.namesService();
    }

    @GET
    public User getById(@QueryParam("id") Long id) {
        return entityManager.find(User.class, id);
    }
}
